#ifndef INETTCP_H
#define INETTCP_H

#include <netinet/tcp.h>
#include "InterfacePackOperation.h"

namespace Pacap {


class InetTcp : public InterfacePackOperation
{
public:
    InetTcp()=default;
    virtual ~InetTcp()=default;

    // InterfacePackOperation interface
public:
    virtual PackType pack() override;
    virtual void unpack(PackType hexData) override;



    u_int16_t getSource() const;
    void setSource(const u_int16_t &value);

    u_int16_t getDest() const;
    void setDest(const u_int16_t &value);

    u_int32_t getSeq() const;
    void setSeq(const u_int32_t &value);

    u_int32_t getAckSeq() const;
    void setAckSeq(const u_int32_t &value);

    u_int16_t getRes1() const;
    void setRes1(const u_int16_t &value);

    u_int16_t getDoff() const;
    void setDoff(const u_int16_t &value);

    PackType getData() const;
    void setData(const PackType &value);

    static size_t getLENGTH();

private:
    struct head
    {
        u_int16_t source;
        u_int16_t dest;
        u_int32_t seq;
        u_int32_t ackSeq;
# if __BYTE_ORDER == __LITTLE_ENDIAN
        u_int16_t res1:4;
        u_int16_t doff:4;
        u_int16_t fin:1;
        u_int16_t syn:1;
        u_int16_t rst:1;
        u_int16_t psh:1;
        u_int16_t ack:1;
        u_int16_t urg:1;
        u_int16_t res2:2;
# elif __BYTE_ORDER == __BIG_ENDIAN
        u_int16_t doff:4;
        u_int16_t res1:4;
        u_int16_t res2:2;
        u_int16_t urg:1;
        u_int16_t ack:1;
        u_int16_t psh:1;
        u_int16_t rst:1;
        u_int16_t syn:1;
        u_int16_t fin:1;
# else
#  error "Adjust your <bits/endian.h> defines"
# endif
        u_int16_t window;
        u_int16_t check;
        u_int16_t urg_ptr;
    } head;

    PackType data;
};

}
#endif // INETTCP_H
